//
//  ViewController.m
//  4发图
//
//  Created by dllo on 16/3/22.
//  Copyright © 2016年 洪振宇. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic, retain) UIScrollView *scrollerView;
@property (nonatomic, retain) UIImageView *image1;
@property (nonatomic, retain) UIImageView *image2;
@property (nonatomic, retain) UIImageView *image3;
@property (nonatomic, retain) UIImageView *image4;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self creatImageView];
    [self creatScrollerView];
    
}
- (void)creatImageView{
    self.image1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    self.image2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    self.image3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    self.image4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 414, 200)];
    self.image1.image = [UIImage imageNamed:@"1.jpg"];
    self.image2.image = [UIImage imageNamed:@"2.jpg"];
    self.image3.image = [UIImage imageNamed:@"3.jpg"];
    self.image4.image = [UIImage imageNamed:@"4.jpg"];
    [self.view addSubview:self.image1];
    [self.view addSubview:self.image2];
    [self.view addSubview:self.image3];
    [self.view addSubview:self.image4];
    
}
- (void)creatScrollerView{
    self.scrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
    self.scrollerView.contentSize = CGSizeMake(self.view.frame.size.width * 4 , 200);
    self.scrollerView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.scrollerView];
    self.scrollerView.pagingEnabled = YES;
    self.scrollerView.delegate = self;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (self.scrollerView.contentOffset.x <= 414) {
        self.image4.alpha = 1 - (self.scrollerView.contentOffset.x/414);
    }
    if (self.scrollerView.contentOffset.x >= 414) {
        self.image3.alpha = 1 - ((self.scrollerView.contentOffset.x- 414)/414 );
    }

}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
